package io.renren;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import com.taobao.api.ApiException;
import com.taobao.api.DefaultTaobaoClient;
import com.taobao.api.TaobaoClient;
import com.taobao.api.request.TbkDgItemCouponGetRequest;
import com.taobao.api.response.TbkDgItemCouponGetResponse;

import io.renren.common.utils.TaobaoAPISignUtil;

@RunWith(SpringRunner.class)
@SpringBootTest
public class taobao {
	String url = "http://gw.api.taobao.com/router/rest";
	String key = "24712890";
	String secret = "60fcf5661dc21e72b37ec6962092a926";
	String sessionId = "6101421d0a4bfb5c2f48f61f6219b1153d52e47c7528a161800948611";

	@Test
	public void contextLoads() throws ApiException {
//		TaobaoClient client = new DefaultTaobaoClient("http://gw.api.taobao.com/router/rest", "24712890", "60fcf5661dc21e72b37ec6962092a926");
		TbkDgItemCouponGetRequest req = new TbkDgItemCouponGetRequest();
//		
		req.setAdzoneId(123L);
//		req.setPlatform(1L);
//		req.setCat("16");
//		req.setPageSize(1L);
//		req.setQ("");
//		req.setPageNo(1L);
//		TbkDgItemCouponGetResponse rasp = client.execute(req);
//		System.out.println("--------------------------------"+rasp.getBody());
//		
		SimpleDateFormat f = new SimpleDateFormat("yyyy-mm-dd HH:MM:ss");
		Map<String, String> params= new HashMap<String, String>();
		params.put("method", "taobao.tbk.dg.item.coupon.get");
		params.put("sign_method", "hmac");
		params.put("app_key", key);
		params.put("timestamp", f.format(new Date()));
		params.put("v", "2.0");
		params.put("adzone_id", "123");
		
		
		try {
			System.out.println(TaobaoAPISignUtil.signTopRequest(params, secret, "hmac"));
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		
		
	}

}
